using System.Collections.Generic;
using UnityEditor;

namespace DA.AnimGraph.Editor {

    public class AGAFileTool {

        public class AssetProcessor : AssetPostprocessor {
            static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
                agaListDirty = true;
            }
        }

        public struct File {
            public string guid;
            public string path;
        }

        public static bool agaListDirty { get; private set; }

        public List<File> agaList {
            get {
                if (agaListDirty || agaListInternal == null) {
                    GetAllAGA();
                }
                return agaListInternal;
            }
        }
        private List<File> agaListInternal;

        internal AGAFileTool() {
            agaListDirty = true;
        }

        void GetAllAGA() {
            string[] guids = AssetDatabase.FindAssets($"t:{nameof(AnimGraphArchiveAsset)}");
            agaListInternal = new List<File>(guids.Length);
            for (int i = 0; i < guids.Length; i++) {
                var f = new File() {
                    guid = guids[i],
                    path = AssetDatabase.GUIDToAssetPath(guids[i])
                };
                agaListInternal.Add(f);
            }
            agaListDirty = false;
        }

    }
}
